﻿<?php
	include '../inc/conn.php';
	session_start();
	extract($_POST);
	extract($_GET);
	unset($_POST,$_GET);

	if(!isset($_SESSION['logname'])){
		die("<div>User Session is missing</div>");
	}
	
	if (isset($act) && isset($id))
	{
		if (empty($kptype) || empty($kpdesc) || empty($kpowner) ||empty($kpnum) ||empty($kppn) || empty($kpstat) || $kptype == "N/A" ){
			echo "<script>alert('有内容不能未空或类型为默认值，请重新填写');window.history.go(-1);</script>";
			die("有内容不能未空或类型为默认值，请重新填写");
		}
		if (empty($kpremark))
			$kpremark='N/A';
	
		if ($act == 'mod')
		{	
			date_default_timezone_set('Asia/Shanghai');
			$dt = date("Y-m-d H:i:s");
			$db = new mysql();
			$table = "eng_repo";
			$condition = "id=".$id;
			$mod_content="KP_TYPE=\"".htmlentities($kptype,ENT_QUOTES)."\", KP_PN=\"".htmlentities($kppn,ENT_QUOTES)."\", 
			KP_DESC=\"".htmlentities($kpdesc,ENT_QUOTES)."\", KP_NUM=\"".htmlentities($kpnum,ENT_QUOTES).
			"\", KP_OWNER=\"".htmlentities($kpowner,ENT_QUOTES)."\", STATUS=\"".htmlentities($kpstat,ENT_QUOTES).
			"\", REMARK=\"".htmlentities($kpremark,ENT_QUOTES)."\", KP_CHECKOUT_DATE=\"".$dt."\"".", DEPT=\"".$iDept."\"";	
			
			$db->update($table, $mod_content, $condition);
			echo "<script>alert('数据更新完成!');window.location='admin_index.php?name=repo'</script>";
			$db->close();
		}
	}
	
	if (!isset($id))
	{
		echo "<script>alert('ID is empty!');</script>";
		die("ID is empty!");
	}
	$db = new mysql();
	$sql = "select * from eng_repo where id=".$id;
	$db->query($sql);
	$num = $db->db_num_rows();
	if ($num == 0)
		die("No data was found!");
	$row = $db->fetch_assoc();
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">-->
<link rel="stylesheet" href="/css/bootstrap.min.css">
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery-migrate.min.js"></script>
<script type="text/javascript" src="/xhEditor/xheditor.min.js"></script>
<script type="text/javascript" src="/xhEditor/xheditor_lang/zh-cn.js"></script>
<script type="text/javascript" src="/js/bootstrap.min.js"></script>
<style>
<!--
.xheDialog label {
	display: inline;
}
.form-horizontal .control-label {
	width: 80px;
}
.form-horizontal .controls {
	margin-left: 20px;
}
-->
</style>
<title>查看 "<? echo htmlspecialchars_decode($row['KP_PN']); ?>" 详细信息</title>
</head>
<body class="background">
<?
	include "admin_top.php";
?>
<div class="container white-background pagecontent">
<div class="panel panel-primary">
    <div class="panel-heading">
        <h3 class="panel-title">修改 "<? echo htmlspecialchars_decode($row['KP_PN']); ?>" 详细信息</h3>
    </div>
    <div class="panel-body">
	<form action="mod_repo.php?id=<?echo $row['ID']?>&act=mod" method="post" enctype="application/x-www-form-urlencoded">
	<div class="input-group">
		<span class="input-group-addon">类型:</span>
		<select name="kptype" id="kptype" class="form-control">
			<option value="整机" <? if ($row['KP_TYPE'] == "整机")  echo 'selected="整机"'; ?>>整机</option>
			<option value="重材" <? if ($row['KP_TYPE'] == "重材")  echo 'selected="重材"'; ?>>重材</option>
			<option value="机构" <? if ($row['KP_TYPE'] == "机构")  echo 'selected="机构"'; ?>>机构</option>
			<option value="电子" <? if ($row['KP_TYPE'] == "电子")  echo 'selected="电子"'; ?>>电子</option>
			<option value="主板" <? if ($row['KP_TYPE'] == "主板")  echo 'selected="主板"'; ?>>主板</option>
		</select>
	</div>
	<div class="input-group">
		<span class="input-group-addon">料号:</span>
		<input name="kppn" type="text" value='<? echo htmlspecialchars_decode($row['KP_PN']); ?>' class="form-control">
	</div>
	<div class="input-group">
		<span class="input-group-addon">描述:</span>
		<input name="kpdesc" type="text" value='<? echo htmlspecialchars_decode($row['KP_DESC']); ?>' class="form-control">
	</div>
	<div class="input-group">
		<span class="input-group-addon">数量:</span>
		<input name="kpnum" type="text" value="<? echo htmlspecialchars_decode($row['KP_NUM']); ?>" class="form-control">
	</div>
	
	<div class="input-group">
		<span class="input-group-addon">状态:</span>
		<select name="kpstat" id="kpstat" class="form-control">
			<option value="借用中" <? if ($row['STATUS'] == "借用中")  echo 'selected="借用中"'; ?>>借用中</option>
			<option value="已归还" <? if ($row['STATUS'] == "已归还")  echo 'selected="已归还"'; ?>>已归还</option>
		</select>
	</div>
	<div class="input-group">
		<span class="input-group-addon">部门:</span>
		<select name="iDept" id="iDept" class="form-control">
			<option value="TE" <? if ($row['DEPT'] == "TE")  echo 'selected="TE"'; ?>>TE</option>
			<option value="ME" <? if ($row['DEPT'] == "ME")  echo 'selected="ME"'; ?>>ME</option>
			<option value="EE" <? if ($row['DEPT'] == "EE")  echo 'selected="EE"'; ?>>EE</option>
			<option value="RT" <? if ($row['DEPT'] == "RT")  echo 'selected="RT"'; ?>>RT</option>
			<option value="PE" <? if ($row['DEPT'] == "PE")  echo 'selected="PE"'; ?>>PE</option>		
			<option value="IE" <? if ($row['DEPT'] == "IE")  echo 'selected="IE"'; ?>>IE</option>					
			<option value="FPM" <? if ($row['DEPT'] == "FPM")  echo 'selected="FPM"'; ?>>FPM</option>
		</select>
	</div>
	<div class="input-group">
		<span class="input-group-addon">保管人:</span>
		<input name="kpowner" type="text" value="<? echo htmlspecialchars_decode($row['KP_OWNER']); ?>" class="form-control">
	</div>
	<div>备注:<br />
		<textarea name="kpremark" id="kpremark" rows="12" cols="80" class="xheditor {tools:'mfull',skin:'default', upImgUrl:'upload.php?immediate=1'}" style="width:940px;height:280px; no-repeat right bottom fixed">
		<? echo htmlspecialchars_decode($row['REMARK']); ?>
		</textarea>
	</div>

<div><input class="btn btn-success btn-primary" name="submit" value="修改" type="submit"><input class="btn btn-danger" name="reset" value="重填" type="reset"></div>
</form>
</div>
</div>
</div>
<?
include '../bottom.php';
?>
</body>
</html>
<?
	$db->close();
?>
